<extend name="common:base" />
<block name="content">
    <div id="header">
        <div class="header">
            <h1 class="tit">{$site_title}</h1>
            <!--<p class="goback">-->
                <!--<a class="return" href="javascript:history.go(-1);">返回</a>-->
            <!--</p>-->
        </div>
    </div>
    <div class="skrwm">
        <div class="skrwm-li">
            <p>{$site_title}</p>
            <notempty name="ewm_code">
            <img src="{$ewm_code}" onclick="getElementById('file').click()" class="code_img"/>
             <else/>
            <img src="{:C('__STATIC__')}{$theme}/Static/img/scrwm.jpg" onclick="getElementById('file').click()" class="code_img"/>
            </notempty>
            <!--<input type="button"  onclick="index.html" value="保存" />-->
            <a href="javascript:;" class="btn">保存</a>
        </div>
    </div>
    <form enctype="multipart/form-data" method="post" action="{:U('Setting/code_upload')}" id="do_upload">
        <input type="hidden" value="{$ewm_code}" id="ewm_code">
        <input type="file" id="file" name='file' class="code_file"/>
        <input type="hidden" name='t' value="{$code_type}" id="t"/>
    </form>
</block>

<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/total.css" />
</block>
<block name="JS">
    <script type="text/javascript" src="__PUBLIC__/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/static/ext/js/jquery.form.js"></script>

    <script type="text/javascript">
        $(function(){
            $("#file").change(function(){

                var file = $('#file').get(0).files[0];
                if (typeof(file) ==  'object') {
                    var reader = new FileReader();
                    reader.readAsDataURL(file);
                    reader.onload=function(e){
                        $('.code_img').attr('src', e.target.result);
                    }
                } else {
                    $('.code_img').attr('src', $('#ewm_code').val());
                }
            });

            $('.btn').click(function(e) {
                 $("#do_upload").ajaxSubmit({
                    url: "{:U('Setting/code_upload')}",
                    type:'post',
                    data: {
                        'img': $('#file').val(),
                        't': $('#t').val()
                    },
                    success: function(msg) {
                        if (msg == 'success') {
                            layer.msg('修改成功!', {icon: 1, time: 500});
                            setTimeout(function() {
                              window.history.go(-1);
                            },500);

                        }
                    }
                 });
            });
        });
    </script>
</block>
